<?php
class newsRecommendInfo extends CWidget
{
	public $htmlOptions = array();

	public $length = 30;
	public $id;
	
	public $dataProvider;
	
	public function getData()
	{
		$result = array();
		$i = 0;
		
		
		$news = Article::model()->findAll(array(
			'condition'=>'arc_isrecommend = :arc_isrecommend',
			'limit'=>5,
			'order'=>'arc_id DESC',
			'params'=>array(
				':arc_isrecommend'=>Article::RECOMMEND_ALLOW
			)
		));
		foreach ($news as $item)
		{
			$i++;
			$result[$i]['category'] = $item->category->cate_name;
			$result[$i]['content'] = UtilTools::strSlice(strip_tags($item->arc_content),0,125);
			$result[$i]['links'] = Yii::app()->createUrl('news/view',array('id'=>$item->arc_id));
			$result[$i]['title'] = CHtml::link($item->arc_title,array('new/view','id'=>$item->arc_id));
			$result[$i]['folder'] = CHtml::link(CHtml::image('/public/images/arc-ico.png',$item->arc_title),array('news/view','id'=>$item->arc_id));
		}
		
		shuffle($result);
		$this->dataProvider = json_encode($result);
		
	}
	
	
	public function run()
	{	
		$this->getData();
		
		$this->render('site',array(
			'dataProvider' => $this->dataProvider
		));
	}
}